package com.es.util.excel;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

public class ExportBaoxiaoExcelJsp {  
	
	private static String excelBodyStart = "<table width=\"100%\" cellpadding='0' cellspacing='0' border='1' bordercolorDark='white' bordercolorLight='#BEBEBE' class=\"datatable\">";
	
	private static String excelBody2 = "<tr class=\"datatr\" >";
	
	private static String excelBodyStd1 = "<td  valign=\"top\" nowrap=\"nowrap\" bgcolor=\"#DAF2FC\" >";
	
	private static String excelBodyStd2 = "<td  valign=\"top\" nowrap=\"nowrap\"  >";
	
	private static String excelBodyEtd = "</td>";
	
	private static String excelBodyEtr = "</tr>";
	
	@SuppressWarnings("unchecked")
	public static String  getExcelJspString(ArrayList<HashMap<String, String>> list,ArrayList<HashMap<String, String>> orderList) throws UnsupportedEncodingException{
			
	
		StringBuffer sb = new StringBuffer();
		String[] key = new String[orderList.size()];
		sb.append(excelBody2);
		String title = "<TD colspan=\"1\" rowspan=\"2\"  bgcolor=\"#DAF2FC\">报销年月</TD>" +
				"<TD colspan=\"1\" rowspan=\"2\"  bgcolor=\"#DAF2FC\">城市</TD>" +
				"<TD colspan=\"1\" rowspan=\"2\"  bgcolor=\"#DAF2FC\">姓名</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\" align=\"center\"  bgcolor=\"#DAF2FC\">常规报销</TD>" +
								"<TD colspan=\"4\" rowspan=\"1\" align=\"center\"  bgcolor=\"#DAF2FC\">差旅费</TD>" +
										"<TD colspan=\"4\" rowspan=\"1\" align=\"center\"  bgcolor=\"#DAF2FC\">杂费</TD>" +
												"<TD colspan=\"1\" rowspan=\"2\"  bgcolor=\"#DAF2FC\">合计</TD>" +
														"<TD colspan=\"1\" rowspan=\"2\"  bgcolor=\"#DAF2FC\">RTM</TD>" +
																"<TD colspan=\"1\" rowspan=\"2\"  bgcolor=\"#DAF2FC\">是否报销</TD>";
		sb.append(title);

		sb.append(excelBodyEtr);
		
		title = "<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">通讯费</TD>" +
				"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">交通</TD>" +
				"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">住宿</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">餐补</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">差旅合计</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">快递费</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">杂费</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">电脑补助</TD>" +
						"<TD colspan=\"1\" rowspan=\"1\"  bgcolor=\"#DAF2FC\">补上月报销</TD>";
		
		sb.append(excelBody2);
		sb.append(title);

		sb.append(excelBodyEtr);
		int i = 0;
		for(HashMap obj:orderList){
			Iterator iterator = obj.keySet().iterator(); 
			while (iterator.hasNext()) { 
				key[i++] = (String)iterator.next();				
			 }
		}
		
		for(HashMap obj:list){
			sb.append(excelBody2);
			Iterator iterator = obj.keySet().iterator(); 
			for(int j = 0;j<key.length;j++) { 
				sb.append(excelBodyStd2);
				sb.append(obj.get(key[j])==null?"":obj.get(key[j])).append(excelBodyEtd); 				
			 }
			sb.append(excelBodyEtr);
			
			
		}
		
		return excelBodyStart+sb.toString()+"</table>";
		
	}

}
